//
//  MBDMsgDetailCell.swift
//  MasterBoy
//
//  Created by kyson on 2023/11/8.
//

import Foundation


import UIKit
import SnapKit
import YYText


class MBDMsgDetailCell : MBDCommonCell {
    
    private var titleLabel : YYLabel!
    private var subtitleLabel : YYLabel!
    
    private var separaterLine : UIView!
        
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        //暂不支持暗黑模式，所有背景颜色都写死
        self.contentView.backgroundColor = UIColor.white
        
        self.initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initialize()
    }
    
    func initialize() {
        
        titleLabel = YYLabel()
        self.contentView.addSubview(titleLabel)
                
        subtitleLabel = YYLabel()
        self.contentView.addSubview(subtitleLabel)
        
        separaterLine = UIView()
        self.contentView.addSubview(separaterLine)
        separaterLine.backgroundColor = UIColor.lightGray
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(8)
            make.width.equalTo(0)
            make.height.equalTo(0)
        }
                
        subtitleLabel.snp.makeConstraints { make in
            make.left.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(5)
            make.right.equalTo(-MBDMainCellModel.marginSubtitleRight)
            make.height.equalTo(0)
        }        
        
        let scale = UIScreen.main.scale
        let h = ceil(0.5 * scale) / scale
        
    }
    
    deinit {
        print("MBDMsgDetailCell was deallocated")
    }
    
    override var cellModel: Any! {
        didSet {
            let realCellModel = cellModel as! MBDMsgDetailCellModel
            
            self.titleLabel.textLayout = realCellModel.titlelayout

            titleLabel.snp.updateConstraints { make in
                make.height.equalTo(realCellModel.titlelayout!.textBoundingSize.height)
                make.width.equalTo(realCellModel.titlelayout!.textBoundingSize.width)
            }

            self.subtitleLabel.textLayout = realCellModel.subtitlelayout

            subtitleLabel.snp.updateConstraints { make in
                make.height.equalTo(realCellModel.subtitlelayout!.textBoundingSize.height)
            }
            
        }
    }
    
}
